<?php

class Solution {

    /**
     * @param Integer[] $nums
     * @return String[]
     */
    function summaryRanges($nums) {
        $len = count($nums);
        $arr = []; $idx = 0;
        for ($i = 0; $i < $len; $i++) {
            if ($i == $len - 1 || $nums[$i] + 1 != $nums[$i + 1]) {
                $arr[] = $idx == $i ? "{$nums[$idx]}" : "{$nums[$idx]}->{$nums[$i]}";
                $idx = $i + 1;
            }
        }
        return $arr;
    }

}

?>
